package com.xxxx.yygh.cmn.controller;

import com.xxxx.yygh.cmn.service.DictService;
import com.xxxx.yygh.common.result.Result;
import com.xxxx.yygh.model.cmn.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author Lee.s
 * @description
 * @date 2021/03/12 7:56
 */
@RestController
@RequestMapping("/admin/cmn/dict")
@Api(tags = "数据字典服务接口")
@CrossOrigin
public class DictController {

    @Autowired
    DictService dictService;

    //根据数据id查询子数据列表
    @ApiOperation(value = "根据数据id查询子数据列表")
    @GetMapping("/findChildData/{id}")
    public Result findChildData(@PathVariable Long id) {
        List<Dict> list = dictService.findChildrenDataById(id);
        return Result.ok(list);
    }

    // 导出数据
    @ApiOperation("导出excel数据")
    @GetMapping("/exportData")
    public void exportData(HttpServletResponse response) throws IOException {
        dictService.exportData(response);
    }

    // 导入数据
    @ApiOperation("导入数据")
    @PostMapping("/importData")
    public Result importData(MultipartFile file) throws IOException {
        dictService.importData(file);
        return Result.ok();
    }

}
